package cn.lingnan.controller;

import cn.lingnan.dao.OrderDao;
import com.mongodb.client.result.DeleteResult;
import lingnan.entity.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderProviderController {
    @Autowired
    private OrderDao orderDao;

    @GetMapping("findAllOrders")
    public List<Order> findAllOrder(){
        System.out.println("::::::::::::::::::::::::");
        List<Order> orders = orderDao.findOrders();
        System.out.println("provider-order::::::::::::::::"+orders);
        return orders;
    }

    @DeleteMapping("/{id}")
    public Boolean deleteById(@PathVariable("id") String id){
        System.out.println("provider delet id is::::::"+id);
        orderDao.deleteById(id);
        return true;
    }

    @PostMapping("save")
    public Order save(@RequestBody Order order){
        return orderDao.insertOrder(order);
    }

}
